package com.slt.android.customview.d2canvas;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;

import com.slt.android.customview.R;

public class D2CanvasActivity extends AppCompatActivity implements View.OnClickListener {

    RelativeLayout rl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_d2canvas);
        rl = (RelativeLayout) findViewById(R.id.rl);
//        setBackGround();
    }

    /**
     * 与xml中设置效果是一样的
     */
    private void setBackGround() {
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.gxt);
        BitmapDrawable mBitmapDrawable = new BitmapDrawable(bitmap);
        mBitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        mBitmapDrawable.setDither(true);
        rl.setBackgroundDrawable(mBitmapDrawable);
    }

    @Override
    public void onClick(View v) {
    }
}
